﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Web_rongmeiti_sys.PublishToRongMeiTi
{
    /// <summary>
    /// 返回消息, Code默认200表示操作成功，500表示异常
    /// </summary>
    /// 2022-1-4 16:16:02 王浩力 添加
    public struct Result
    {
        /// <summary>
        /// 操作代码，默认200表示操作成功，500表示异常
        /// </summary>
        public int Code;

        /// <summary>
        /// 消息
        /// </summary>
        public string Msg;

        /// <summary>
        /// 返回数据
        /// </summary>
        public object Data;

        /// <summary>
        /// code=200，表示成功
        /// </summary>
        /// <param name="data"></param>
        public Result(object data)
        {
            Code = 200;
            Data = data;
            Msg = "操作成功";
        }

        /// <summary>
        /// code=200，表示操作成功
        /// </summary>
        /// <param name="code"></param>
        public Result(bool success)
        {
            Code = 200;
            Msg = "操作成功";
            Data = null;
        }

        public Result(string msg, int code = 500)
        {
            Code = code;
            Msg = msg;
            Data = null;
        }

        public Result(object data, int code = 200)
        {
            Code = code;
            Data = data;
            Msg = "操作成功";
        }

        public Result(object data, string msg = "", int code = 200)
        {
            Code = code;
            Msg = msg;
            Data = data;
        }
    }

    public struct Result<T>
    {
        /// <summary>
        /// 操作代码，默认200表示操作成功，500表示异常
        /// </summary>
        public int Code;

        /// <summary>
        /// 返回数据，强类型
        /// </summary>
        public T Data;

        /// <summary>
        /// 消息
        /// </summary>
        public string Msg;

        public Result(T data)
        {
            Code = 200;
            Data = data;
            Msg = "操作成功";
        }
     
        public Result(string msg, int code = 500)
        {
            Code = code;
            Msg = msg;
            Data = default;
        }

        public Result(T data, int code = 200)
        {
            Code = code;
            Data = data;
            Msg = "操作成功";
        }

        public Result(T data, string msg = "", int code = 200)
        {
            Code = code;
            Msg = msg;
            Data = data;
        }
    }
}
